import axios from 'axios';

let baseURL = ''
if (import.meta.env.MODE == 'development') {
    baseURL = '/withdraw'; // 测试url
}

console.log("运行环境:",import.meta.env.MODE,';根域名:',baseURL);

axios.defaults.baseURL = baseURL
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
axios.defaults.timeout = 1000000000 // 超时时间
// axios.defaults.withCredentials = true; // 允许携带cookie

// 请求头携带token
let obj = {
  token      : localStorage.getItem('token'),
  loginid    : localStorage.getItem('loginid'),
  flag       : localStorage.getItem('flag')
}
axios.defaults.headers.common['Authorization'] = JSON.stringify(obj)

// 设置axios拦截器  
axios.interceptors.response.use(  
  response => response, // 如果响应状态码在2xx范围内，则直接返回响应  
  error => {  
    // 如果401则跳转到错误页
    if (error.response && error.response.status === 401) {  
        window.location.href = `${window.location.origin}/#/error`
    }  
    // 对于其他错误，返回Promise.reject()以便调用者可以处理错误  
    return Promise.reject(error);  
  }  
);

// 获取付款账号信息
export const getPayInfo = ()=>axios.get(`/withdraw/getGroupUserList`)
// 发送短信验证码
export const sendYZM = (str:string)=>axios.get(`/withdraw/sendMessage?shopId=${str}`)
// 立即付款
export const setPayInfo = (params:object)=>axios.post(`/withdraw/groupWithdrawal`, params)
// 查询余额  
export const getBalance = ()=>axios.get(`/withdraw/getBalance`)
// 获取表格数据
export const getTableData = (params:object)=>axios.post(`/withdraw/getFlowList?`, params)
// 获取收入数据
export const getIncomeFlowList = (params:object)=>axios.post(`/withdraw/getIncomeFlowList?`, params)
// 最后登录时间
export const getLastLoginTime = (params:object)=>axios.post(`/withdraw/getLoginUserInfo`, params)
// 获取shopid
export const getShopId = (params:object)=>axios.post(`/Order/curAccount`, params)
// 获取账户列表
export const getBalanceAcctIdList = ()=>axios.get(`/withdraw/getBalanceAccountList`)

// 云直通用户新增
export const addUser = (params:FormData)=>axios.post(`/withdraw/yztAddOpenPlatform`, params,{
    headers: {'Content-Type': 'multipart/form-data'}
  })
// 云直通用户信息查询
export const yztGetUserDetail = (params:string)=>axios.get(`/withdraw/yztGetUserDetail?shopId=${params}`)

